//
//  UINavigationController+Extension.m
//  New_Runway
//
//  Created by NewLife on 2018/3/8.
//  Copyright © 2018年 NelsonJ. All rights reserved.
//

#import "UINavigationController+Extension.h"

@implementation UINavigationController (Extension)

- (void)safePopViewControllerWithClassName:(NSString *)className {
    
    if ([self.viewControllers[self.viewControllers.count - 2] isKindOfClass:NSClassFromString(className)]) {
        
        [self popViewControllerAnimated:YES];
        return;
    }
    
    for (NSInteger i = self.viewControllers.count - 1; i >= 0; i--) {
        
        UIViewController *vc = self.viewControllers[i];
        
        if ([vc isKindOfClass:NSClassFromString(className)]) {
            
            [self popToViewController:vc animated:YES];
            break;
        }
    }
}

- (void)safePopViewControllerWithClass:(Class)cls {
    
    if ([self.viewControllers[self.viewControllers.count - 2] isKindOfClass:cls]) {
        
        [self popViewControllerAnimated:YES];
        return;
    }
    
    for (NSInteger i = self.viewControllers.count - 1; i >= 0; i--) {
        
        UIViewController *vc = self.viewControllers[i];
        
        if ([vc isKindOfClass:cls]) {
            
            [self popToViewController:vc animated:YES];
            break;
        }
    }
}

@end
